#ifndef __SETTING__
#define __SETTING__

#include <rtthread.h>
#include <netdev_ipaddr.h>

#define GET_BIT_OF(v,n) (((v)&(1<<(n)))?1:0)

//功能类型
typedef enum fun_type
{
    //TCP透传
    FUN_TYPE_TCP_TRANSPARENT = 0x00,
    //UDP透传
    FUN_TYPE_UDP_TRANSPARENT,
    //TCP转RTU
    FUN_TYPE_TCP2RTU,
    //RS232转RS485
    FUN_TYPE_232C485,
    //MQTT转RTU
    FUN_TYPE_MQTT2RTU,
}fun_type;
//网卡类型
typedef enum netdev_type
{
    //EC600
    NETDEV_TYPE_EC600 = 0x00,
    //W5500
    NETDEV_TYPE_W5500,
    //ESP8266
    NETDEV_TYPE_ESP8266,
}netdev_type;
//平台类型
typedef enum platform_type
{
    //my
    PLATFORM_TYPE_MY = 0x00,
    //aliyun
    PLATFORM_TYPE_ALIYUN,
    //ctwing
    PLATFORM_TYPE_CTWING,
    //onenet
    PLATFORM_TYPE_ONENET,
}platform_type;

//串口参数
struct uart_param
{
    //波特率
    int baud;
    //校验位
    uint8_t parity;
    //数据位
    uint8_t data_bit;
    //停止位
    uint8_t stop_bit;
};
#pragma pack(1)
typedef struct uart_param uart_param;

//网卡参数
struct netdev_param
{
    //网卡类型 0 蜂窝 1 以太网 2 wifi
    uint8_t netdev_type;
    //dhcp
    uint8_t dhcp;
    //ip地址
    ip_addr_t ip_addr;
    //指望掩码
    ip_addr_t netmask;
    //网关
    ip_addr_t gw;
    //dns
    ip_addr_t dns_servers[2];
    //mac地址
    uint8_t hwaddr[8];
};
#pragma pack(1)
typedef struct netdev_param netdev_param;
//蜂窝参数
struct cellular_param
{
    //apn
    char apn[10];
};
#pragma pack(1)
typedef struct cellular_param cellular_param;
//wifi阐述
struct wifi_param
{
    //名称
    char ssid[32];
    //密码
    char password[17];
};
#pragma pack(1)
typedef struct wifi_param wifi_param;

//服务端参数
struct server_param
{
    //host
    char host[16];
    //端口
    int port;
};
#pragma pack(1)
typedef struct server_param server_param;
//设备参数
struct device_param
{
    //功能类型
    uint8_t fun_type;
    //功能使能 client/server
    uint8_t fun_enable;
    //使用的下位设备
    uint8_t down_dev;
    //平台
    uint8_t platform_type;
    //串口3参数
    uart_param rs232_params;
    //串口3参数
    uart_param rs485_params;
    //网卡参数
    netdev_param netdev_params;
    //蜂窝参数
    cellular_param cellular_params;
    //wifi参数
    wifi_param wifi_params;
    //服务器参数
    server_param server_params;
};

#pragma pack(1)
typedef struct device_param *device_param_t;

void setting_init(void);
void setting_set_default(void);
void get_device_id(uint32_t *mcu_id);

#endif
